<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>数据库交互</title>
    <!-- Bootstrap -->
    <link href="bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">

  </head>
  <body>
  <h1>数据列表</h1>
  <form action= "c.php" method = "get">
  <button class="btn btn-lg btn-default" type="submit">添加</button>
    

<?php
header("content-type:text/html;charset=utf-8");

class db1{
  private $localhost = "localhost";
  private $name = "root";
  private $code = "root";
  private $database = "pro";
  private $con;


function connect(){
  $this->con = mysql_connect($this->localhost,$this->name,$this->code);
  mysql_select_db($this->database,$this->con);
  mysql_query("set names utf8");
}

function __construct(){
    $this->connect();
}

// function __destruct(){
//     mysql_close($this->con);
// }

function myarray($result){
  while($tmp=mysql_fetch_array($result,MYSQL_ASSOC)){
  $list[] = $tmp;
  }
  return $list;
}

function select($table,$cd){
  return mysql_query("select * from $table $cd");
}
function insert($table,$fields,$value){
   mysql_query("insert into $table $fields values $value");
}
function update($table,$change,$cd){
  mysql_query("update $table set $change where $cd");
}
function delete($table,$cd){
  mysql_query("delete from $table $cd");
}

}

$db = new db1();
//$db->update("product","title='yy'","title='ff'");
$select = $db->select("product","");
$list = $db->myarray($select);
?>


<table class="table table-bordered">
    <thead>
    <tr>
        <th>ID</th>
    <th>名称</th>
    <th>标题</th>
    <th>类型</th>
    <th>价格</th>
    <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($list as $k=>$v){?>
    <tr>
        <td><?php echo $v['id'];?></td>
        <td><?php echo $v['named'];?></td>
        <td><?php echo $v['title'];?></td>
        <td><?php echo $v['type'];?></td>
        <td><?php echo $v['price'];?></td>
        <td><a href="a.php?id=<?php echo $v['id'];?>"><span class="label label-info">修改</span></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="b.php?id=<?php echo $v['id'];?>"><span class="label label-danger">删除</span></a></td>
    </tr>
    </tbody>
    <?php } ?>
</table>

<?php
header("content-type:text/html;charset=utf-8");

class db2{
  private $localhost = "localhost";
  private $name = "root";
  private $code = "root";
  private $database = "pro";
  private $con;
  private $rs;
  private $myrow;
  private $numrows;
  private $pages;
  private $page;
  private $first=1;
  private $prev;
  private $next;
  private $last;



function connect(){
  $this->con = mysql_connect($this->localhost,$this->name,$this->code);
  mysql_select_db($this->database,$this->con);
  mysql_query("set names utf8");
}

function __construct(){
    $this->connect();
}

function __destruct(){
    mysql_close($this->con);
}

function p($pagesize){
$this->rs = mysql_query("select count(*) from product",$this->con);
$this->myrow = mysql_fetch_array($this->rs);
$this->numrows = $this->myrow[0];

$this->pages = intval($this->numrows/$pagesize);
if($this->numrows%$pagesize) 
$this->pages++;
$this->page = isset($_GET['page'])?$_GET['page']:1;


echo "<div align='center'>共有"."{$this->pages}"."页(".$this->page."/".$this->pages.")";
      $this->first;
      $this->prev=$this->page-1;
      $this->next=$this->page+1;
      $this->last=$this->pages;

      if ($this->page > 1){
      echo '<a href="shi.php?page='.$this->first.'">首页</a>';
        echo '<a href="shi.php?page='.$this->prev.'">上一页</a>';
      }
      if ($this->page < $this->pages){
              echo '<a href="shi.php?page='.$this->next.'">下一页</a>';
              echo '<a href="shi.php?page='.$this->last.'">尾页</a>';
      }


}
}

$dbc = new db2();
$dbc->p('1');




?>























